#import "Example8ViewController.h"

@implementation Example8ViewController

@synthesize field1;

-(NSString *)pathOfFile
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docFolder = [paths objectAtIndex:0];
    return [docFolder stringByAppendingFormat:@"myfile.plist"];
}

-(void)applicationWillTerminate:(NSNotification*)notification
{
    NSMutableArray *array = [[NSMutableArray alloc]init];
    [array addObject:field1.text];
    [array writeToFile:[self pathOfFile] atomically:YES];
    [array release];
}




// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
    NSString *path = [self pathOfFile];
    
    if ([[NSFileManager defaultManager]fileExistsAtPath:path])
    {
        NSArray *array = [[NSArray alloc]initWithContentsOfFile:path];
        field1.text = [array objectAtIndex:0];
        [array release];
    }
    
    UIApplication *app = [UIApplication sharedApplication];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
    
    
    [super viewDidLoad];
}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
